package com.suse.warmstill.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.common.utils.UserIdThreadLocal;
import com.suse.warmstill.entity.TbUserinfo;
import com.suse.warmstill.service.CosService;
import com.suse.warmstill.service.UserInfoService;
import com.suse.warmstill.service.UserSefvice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 黄靖
 * @author 2022-11-05 09:40
 * description:
 **/
@Slf4j
@RestController
@Api(tags = "公共的个人信息管理")
@RequestMapping("/warmstill/userInfos")
public class UserInfoApi {
    @Resource
    private UserInfoService userInfoService;


    @PostMapping("/updatePhoto")
    @ApiOperation("修改头像，返回头像地址")
    public CallResult updatePhoto(MultipartFile file) {
        Long id = UserIdThreadLocal.get();

        String photoAdress = userInfoService.upload(id, file);
        return CallResult.success(photoAdress);
    }


    @GetMapping("/getUserInfo")
    @ApiOperation("根据获取到用户的 基本信息")
    public CallResult<TbUserinfo> getUserInfo() {
        //
        final Long id = UserIdThreadLocal.get();


        TbUserinfo userinfo = userInfoService.getUserInfo(id);
        return CallResult.success(userinfo);
    }

    @PostMapping("/updateuserInfo")
    @ApiOperation("用户修改自己的信息")
    public CallResult updateUserInfo(@RequestBody TbUserinfo userinfo) {
       final Long id = UserIdThreadLocal.get();

        userinfo.setUserId(id);
        userInfoService.update(userinfo);
        return CallResult.success();
    }


}
